/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-01-12 09:35:49
 * @LastEditTime : 2023-07-18 13:31:35
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\WechatMenu.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, WeChatPageSet } from '../Common/options'
import { WeChatMenuConversion } from '../Common/Conversion'
import { SynchronizationExtra } from '../../../Configure/WeChatModule'

export const WechatMenu = async ({ url, OptionsEvent, ClientData }) => {
    const parentUuid = await WeChatMenuConversion()
    let data = {
        type: '系统配置',
        pageSize: 10000,
        params: { pageIndex: 1 },
        get: API_LIST()['getWechatMenuTree'],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        hideInSearch: true,
        // exportExcel: true,
        options: [
            <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增小程序菜单" />,
            <SynchronizationExtra />,
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.tableName, title: '菜单名称' },
            { ...commonTableList.sortId, rules: true },
            {
                ...commonTableList.parentUuid,
                fieldProps: {
                    fieldNames: { label: 'tableName', value: 'uuid' },
                    options: parentUuid,
                },
            },
            { ...commonTableList.isEnabled, rules: true },
            {
                dataIndex: 'type',
                title: '类型',
                width: 100,
                rules: true,
                valueType: 'select',
                valueEnum: BuiltInData.MenuType,
                hideInSearch: true,
            },
            {
                dataIndex: 'targetUrl',
                title: '页面地址',
                valueType: 'input',
                rules: true,
                width: 200,
                judge: '0',
                judgeType: 'type',
                hideInTable: true,
            },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 320,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { type, parentUuid, uuid } = record
                    const notMenu = ['d9b18d92-2f3d-41c8-a82a-0777bb90be80']
                    return [
                        type !== 1 && (
                            <AddDataButton
                                OptionsEvent={OptionsEvent}
                                key="addMenu"
                                url={url}
                                title="追加"
                                AddTo={{ key: 'parentUuid', uuid }}
                            />
                        ),
                        notMenu.indexOf(uuid) === -1 &&
                            parentUuid === '00000000-0000-0000-0000-000000000000' &&
                            type === 0 && <WeChatPageSet key="menuSetup" title="页面配置" data={record} />,
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="delete"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
